package com.triangulator;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

public class Helper extends Activity 
{
	private static final String TAG = "Helper";
	
	public static final byte HELP_SPLASH = 0;
	public static final byte HELP_TRIANG = 1;
	public static final byte HELP_REIDENT = 2;
	public static final byte HELP_MAX = 3;

	private int mCurrentScreen = 0;

	private TextView titleText;
	private ImageView image;
	private TextView text;
	private ScrollView myScrollView;
	private Button back;
	private Button next;
	
	public void onCreate(Bundle savedInstanceState)
	{
		if(savedInstanceState != null)
		{
			super.onRestoreInstanceState(savedInstanceState);
			
			mCurrentScreen = savedInstanceState.getInt("myPage");
		}
		
		super.onCreate(savedInstanceState);

		setContentView(R.layout.helper);

		titleText = (TextView) findViewById(R.id.helper_title);
		image = (ImageView) findViewById(R.id.helper_image);
		
		text = (TextView) findViewById(R.id.helper_view);
		myScrollView = (ScrollView) findViewById(R.id.ScrollView);
		
		back = (Button) findViewById(R.id.help_back);
		next = (Button) findViewById(R.id.help_next);
		
		updateContent();
	}
	
	@Override
	public void onSaveInstanceState(Bundle savedInstanceState) {
	  
		savedInstanceState.putInt("myPage", mCurrentScreen);

		super.onSaveInstanceState(savedInstanceState);
	}

	
	private void updateContent() {
		
		Log.d(TAG, "CurrentScreen: " + mCurrentScreen);
		
		if(mCurrentScreen == HELP_SPLASH)
		{
			back.setVisibility(View.GONE);
		}
		else if(mCurrentScreen == HELP_REIDENT)
		{
			next.setVisibility(View.GONE);
		}
		else
		{
			back.setVisibility(View.VISIBLE);
			next.setVisibility(View.VISIBLE);
		}
		
		switch(mCurrentScreen) {
		case HELP_SPLASH:
			titleText.setText("Welcome to TRIANGULATOR");
			image.setImageResource(R.drawable.helper_splash);
			text.setText("The application where you and a friend can locate a distant object on GPS.\n\n" +
					"From the splash screen shown above, you can access:\n\n" +
					" 1. This tutorial\n\n" +
					" 2. The Triangulator: Used when you both know what you're triangulating\n\n" +
					" 3. The Re-identificator: Used when one of you knows what you're looking for, " +
					" and the other only knows the general direction\n\n" +
					"Click below to find out more.\n");
			break;
		case HELP_TRIANG:
			titleText.setText("Using Triangulator");
			image.setImageResource(R.drawable.helper_triangulator);
			text.setText("Steps for Triangulation:\n\n" +
					"1. Connect devices using Bluetooth by pressing the Menu button, then \"Make discoverable\", followed by \"Connect a Device\".\n\n" +
					"2. Check connectivity. Connectivity changes are displayed via Toast message.\n\n" + 
					"3. Point camera at object using crosshairs.\n\n" +
					"4. Press either camera button to record and transmit GPS position and orientation.\n\n" +
					"5. Check number of recorded location and bearing readings.\n\n" +
					"6. Access map by pressing on screen button or swiping left or right.\n\n" +
					"7. Press onscreen button to reset measurements.\n");
			break;
		case HELP_REIDENT:
			titleText.setText("Using Re-identificator");
			image.setImageResource(R.drawable.helper_reidentificator);
			text.setText("Steps for Re-identification:\n\n" +
					"1. Connect devices using Bluetooth by pressing the Menu button, then \"Make discoverable\" and then \"Connect a Device\".\n\n" +
					"2. Check connectivity.  Connectivity changes are displayed via Toast message.\n\n" + 
					"3a. Master user fills box with object to be reidentified.\n\n" +
					"3b. Slave user triggered to take picture, then a box is put around the identified object.\n\n" + 
					"4. Press camera button to record GPS position and orientation and analyze subimage.\n\n" +
					"5. Check number of recorded location and bearing readings.\n\n" +
					"6. Access map by pressing on screen button or swiping left or right.\n\n" +
					"7. Restart camera preview to select next object.\n");
			break;
		}
	}

	public void previousScreen(View view) {
		
		if(mCurrentScreen <= 0)
			finish();
		else
		{
			mCurrentScreen--;
			updateContent();
		}
		
		myScrollView.scrollTo(0, 0);
	}

	public void nextScreen(View view) {
		
		if(mCurrentScreen > HELP_MAX)
			finish();
		else
		{
			mCurrentScreen++;
			updateContent();
		}
		
		myScrollView.scrollTo(0, 0);
	}
	
	public void exitScreen(View view) {
			finish();
	}
}
